<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\doctor\controller;

use think\Db;
use cmf\controller\RestBaseController;
use think\Config;
use think\Cache;
use \Qcloud\sms\SmsSingleSender AS sms;

class ServiceController extends RestBaseController
{

    
    public $data;
    public $bizid;
    public $type;
    public $tel;
    public $limit = 10;
    public $doc_id;
    public $doc_ids;

    public function __construct(){
        $token =  input('token') ? input('token') : $_SERVER['HTTP_TOKEN'];
        $appid =  input('appid') ? input('appid') : $_SERVER['HTTP_APPID'];
        if(!$token){
            $this->error('缺少:token');
        }
        if(!Cache::get($token)){
            echo json_encode(array('code'=>90001,'msg'=>'token已过期'));die;
        }
        preg_match_all('/\d+/',$token,$arr);
        if(count(@$arr[0]) != 3){
            $this->error('token:有误!');
        }
        if($arr[0][2] == 2){//如果是医生
                $bizid = Db::prefix_close()->table('doctor')
                    ->where(['tel'=>$arr[0][1]])
                    ->field('biz_id,id')
                    ->find();
            $doc_id = $bizid['id'];
            $bizid = $bizid['biz_id'];
            $this->type= 2;
        }else{//如果是助手 就只返回他的医生的数据
            $hep = Db::prefix_close()->table('helper')
                    ->where(['tel'=>$arr[0][1]])
                    ->field('biz_id,doc_id')
                    ->find();
            $bizid = $hep['biz_id'];
            $doc_id = $hep['doc_id'];
            $this->type = 3;
        }
        $this->doc_id = isset($doc_id) ? 'c.id = '.$doc_id : '';
        $this->doc_ids = isset($doc_id) ? $doc_id : '';
        $this->bizid = $bizid;
        $this->data = input();
    }
    
    /**
     * [index ]
     * @return [type] [description]
     */
    public function index(){
        $a  = Db::table('default_roster')->select();
        $this->success('暂无数据',array());
        // print_r($a);
    }
}